package com.yangle.frame.admin.service;

import com.yangle.frame.admin.entity.FrameMenu;
import com.yangle.frame.admin.mapper.FrameMenuMapper;
import com.yangle.frame.common.service.BaseService;
import com.yangle.frame.common.utils.MapperUtils;
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.StringUtil;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * Created by yangle on 2018/5/27.
 */
@Service
public class FrameMenuService implements BaseService<FrameMenu>{
    @Autowired
    private FrameMenuMapper frameMenuMapper;
    @Override
    public List<FrameMenu> getAll(FrameMenu menu){
        Example example=MapperUtils.getExampleByClass(FrameMenu.class,menu);
        return frameMenuMapper.selectByExample(example);
    }

    public List<FrameMenu> getMainMenu(){
        Example example=new Example(FrameMenu.class);
        example.createCriteria().andEqualTo("isMain","true");
        return frameMenuMapper.selectByExample(example);
    }

    public List<FrameMenu> getLeftMenu(){
        Example example=new Example(FrameMenu.class);
        example.createCriteria().andEqualTo("isOpen","true");
        return frameMenuMapper.selectByExample(example);
    }
    public void create(FrameMenu frameMenu){
        frameMenuMapper.insert(frameMenu);
    }
    public void update(FrameMenu frameMenu){
        frameMenuMapper.updateByPrimaryKey(frameMenu);
    }

public FrameMenu select(String id){
        return frameMenuMapper.selectByPrimaryKey(id);
}
public void updateIsOpen(String id,String isOpen){
    frameMenuMapper.updateIsOpen(id,isOpen);
}
public void delete(String ids){
    frameMenuMapper.deletes(Arrays.asList(ids.split(",")));
}}
